package com.link.gateway.core.comproperty;

import com.link.gateway.core.utils.YmlConstants;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * @author HuangLJ
 * @date 2019-07-30 11:56
 * yml信息属性配置
 */

@Component
@Scope
public class YmlProperties {

    @Value("${application.aes.secret}")
    private String aesSecretkey;
    /**
     * redis单节点
     */
    @Value("${spring.redis.host}")
    private String redisHost;
    @Value("${spring.redis.password}")
    private String redisPassword;
    @Value("${spring.redis.port}")
    private String redisPort;

    /**
     * redis集群相关属性
     * @throws Exception
     */
    @Value("${spring.redis.cluster.expireSeconds}")
    private int redisClusterExpireSeconds;
    @Value("${spring.redis.cluster.commandTimeout}")
    private int redisClusterCommandTimeout;
    @Value("${spring.redis.cluster.nodes}")
    private String clusterNodes;
    @Value("${spring.redis.cluster.password}")
    private String redisClusterPassword;
    @Value("${spring.redis.cluster.state}")
    private boolean applicationRedisClusterState;

    @Value("${spring.redis.pool.max-idle}")
    private int redisPoolMaxIdle;
    @Value("${spring.redis.pool.min-idle}")
    private int redisPoolMinIdle;
    @Value("${spring.redis.pool.max-total}")
    private int redisPoolMaxTotal;
    @Value("${spring.redis.pool.max-wait}")
    private int redisPoolMaxWait;
    @Value("${application.visitlog.env}")
    private String visitLogEnv;
    /** 全局接口访问记录开关 */
    @Value("${application.visitlog.switch}")
    private String visitLogSwitch;

    //是否记录方法执行时间
    @Value("${function.time}")
    private boolean isRecord;

    @Value("${id.datacenterid}")
    private long dataCenterId;
    @Value("${id.machineid}")
    private long machineId;

    @Value("${spring.mail.username}")
    private String emailFrom;

    public void afterPropertiesSet() {
        /**
         * 设置redis变量
         */
        YmlConstants.setApplicationRedisPassword(redisPassword);
        YmlConstants.setApplicationRedisHost(redisHost);
        YmlConstants.setApplicationRedisPort(redisPort);

        YmlConstants.setAesSecretkey(aesSecretkey);
        /**
         * 设置redis集群变量
         */
        YmlConstants.setRedisClusterCommandTimeout(redisClusterCommandTimeout);
        YmlConstants.setRedisClusterExpireSeconds(redisClusterExpireSeconds);
        YmlConstants.setRedisClusterNodes(clusterNodes);
        YmlConstants.setRedisClusterPassword(redisClusterPassword);
        YmlConstants.setApplicationRedisClusterState(applicationRedisClusterState);

        /**
         * 设置redis连接池
         */
        YmlConstants.setRedisPoolMaxIdle(redisPoolMaxIdle);
        YmlConstants.setRedisPoolMinIdle(redisPoolMinIdle);
        YmlConstants.setRedisPoolMaxTotal(redisPoolMaxTotal);
        YmlConstants.setRedisPoolMaxWait(redisPoolMaxWait);

        YmlConstants.setVisitLogEnv(visitLogEnv);
        YmlConstants.setVisitLogSwitch(visitLogSwitch);
        YmlConstants.setIsRecord(isRecord);

        YmlConstants.setDataCenterId(dataCenterId);
        YmlConstants.setMachineId(machineId);

        YmlConstants.setEmailFrom(emailFrom);
    }

}
